/*
 * @Author: dfh
 * @Date: 2024-10-17 10:35:12
 * @LastEditors: dfh
 * @Modified By: dfh
 * @describe:
 */
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
import ElementPlus from "unplugin-element-plus/vite";
import UnoCss from "unocss/vite";

// https://vitejs.dev/config/
export default defineConfig({
  resolve: {
    alias: [
      {
        find: "@",
        replacement: path.resolve(__dirname, "src")
      }
    ]
  },
  plugins: [
    vue(),
    UnoCss(),
    //自动导入
    AutoImport({
      //顺便自动导入 vue 和 vue-router
      imports: ["vue", "vue-router", "pinia"],
      resolvers: [ElementPlusResolver()],
      //生成的全局变量放到次目录下
      dts: "src/auto-import.d.ts",
      //解决eslint对getCurrentInstance这类的报错
      //true后会生成一次 .eslintrc-auto-import.json文件，后续不需要再生成，改为false
      eslintrc: { enabled: false }
    }),
    Components({
      //默认只针对src/components目录实现自动导入
      //布局组件也有相关的组件希望自动导入
      dirs: ["src/components", "src/layout/components"],
      resolvers: [ElementPlusResolver()],
      //自动生成的组件类型放到这里
      dts: "src/components.d.ts"
    }),
    ElementPlus({})
  ]
});
